home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
util
/
httplib2
/
iri2uri.pyo
(
.txt
)
< prev
Wrap
Python Compiled Bytecode
|
2008-10-13
|
3KB
|
84 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__author__ = 'Joe Gregorio (joe@bitworking.org)'
__copyright__ = 'Copyright 2006, Joe Gregorio'
__contributors__ = []
__version__ = '1.0.0'
__license__ = 'MIT'
__history__ = '\n'
import urlparse
escape_range = [
(160, 55295),
(57344, 63743),
(63744, 64975),
(65008, 65519),
(65536, 131069),
(131072, 196605),
(196608, 262141),
(262144, 327677),
(327680, 393213),
(393216, 458749),
(458752, 524285),
(524288, 589821),
(589824, 655357),
(655360, 720893),
(720896, 786429),
(786432, 851965),
(851968, 917501),
(921600, 983037),
(983040, 1048573),
(1048576, 1114109)]
def encode(c):
retval = c
i = ord(c)
for low, high in escape_range:
if i < low:
break
if i >= low and i <= high:
retval = []([ '%%%2X' % ord(o) for o in c.encode('utf-8') ])
break
continue
[]
return retval
def iri2uri(uri):
return uri
if __name__ == '__main__':
import unittest
class Test(unittest.TestCase):
def test_uris(self):
invariant = [
u'ftp://ftp.is.co.za/rfc/rfc1808.txt',
u'http://www.ietf.org/rfc/rfc2396.txt',
u'ldap://[2001:db8::7]/c=GB?objectClass?one',
u'mailto:John.Doe@example.com',
u'news:comp.infosystems.www.servers.unix',
u'tel:+1-816-555-1212',
u'telnet://192.0.2.16:80/',
u'urn:oasis:names:specification:docbook:dtd:xml:4.1.2']
for uri in invariant:
self.assertEqual(uri, iri2uri(uri))
def test_iri(self):
self.assertEqual('http://xn--o3h.com/%E2%98%84', iri2uri(u'http://\xe2\x98\x84.com/\xe2\x98\x84'))
self.assertEqual('http://bitworking.org/?fred=%E2%98%84', iri2uri(u'http://bitworking.org/?fred=\xe2\x98\x84'))
self.assertEqual('http://bitworking.org/#%E2%98%84', iri2uri(u'http://bitworking.org/#\xe2\x98\x84'))
self.assertEqual('#%E2%98%84', iri2uri(u'#\xe2\x98\x84'))
self.assertEqual('/fred?bar=%E2%98%9A#%E2%98%84', iri2uri(u'/fred?bar=\xe2\x98\x9a#\xe2\x98\x84'))
self.assertEqual('/fred?bar=%E2%98%9A#%E2%98%84', iri2uri(iri2uri(u'/fred?bar=\xe2\x98\x9a#\xe2\x98\x84')))
self.assertNotEqual('/fred?bar=%E2%98%9A#%E2%98%84', iri2uri(u'/fred?bar=\xe2\x98\x9a#\xe2\x98\x84'.encode('utf-8')))
unittest.main()